package org.achartengine.internal;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Build;
import android.os.Handler;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import org.achartengine.internal.chart.k;
import org.achartengine.internal.model.ValueObject;
import org.achartengine.internal.renderer.XYMultipleSeriesRenderer;

/* loaded from: classes2.dex */
public class GraphicalView extends View {
    private static final int k = Color.argb(175, 150, 150, 150);
    GestureDetector a;
    private org.achartengine.internal.chart.a b;
    private XYMultipleSeriesRenderer c;
    private Rect d;
    private Handler e;
    private RectF f;
    private Bitmap g;
    private Bitmap h;
    private Bitmap i;
    private int j;
    private org.achartengine.internal.a.d l;
    private org.achartengine.internal.a.d m;
    private org.achartengine.internal.a.b n;
    private Paint o;
    private ITouchHandler p;

    public GraphicalView(Context context, org.achartengine.internal.chart.a aVar) {
        super(context);
        int i;
        this.d = new Rect();
        this.f = new RectF();
        this.j = 50;
        this.o = new Paint();
        this.a = null;
        this.b = aVar;
        this.e = new Handler();
        org.achartengine.internal.chart.a aVar2 = this.b;
        if (aVar2 instanceof k) {
            XYMultipleSeriesRenderer e = ((k) aVar2).e();
            this.c = e;
            if (e.W()) {
                this.g = BitmapFactory.decodeStream(getClass().getResourceAsStream("image/zoom_in.png"));
                this.h = BitmapFactory.decodeStream(getClass().getResourceAsStream("image/zoom_out.png"));
                this.i = BitmapFactory.decodeStream(getClass().getResourceAsStream("image/zoom-1.png"));
            }
            if (this.c.Z() == 0) {
                this.c.h(this.o.getColor());
            }
            if (this.c.U() || this.c.V()) {
                this.l = new org.achartengine.internal.a.d((k) this.b, true, this.c.X());
                this.m = new org.achartengine.internal.a.d((k) this.b, false, this.c.X());
                this.n = new org.achartengine.internal.a.b((k) this.b);
            }
            try {
                i = Integer.valueOf(Build.VERSION.SDK).intValue();
            } catch (Exception unused) {
                i = 7;
            }
            if (i < 7) {
                this.p = new e(this, this.b);
            } else {
                this.p = new d(this, this.b);
            }
        }
    }

    public GestureDetector a() {
        return this.a;
    }

    public void setGestureDetector(GestureDetector gestureDetector) {
        this.a = gestureDetector;
    }

    @Override // android.view.View
    protected void onDraw(Canvas canvas) {
        int i;
        super.onDraw(canvas);
        canvas.getClipBounds(this.d);
        int i2 = this.d.top;
        int i3 = this.d.left;
        int width = this.d.width();
        int height = this.d.height();
        this.b.a(canvas, i3, i2, width, height, this.o);
        XYMultipleSeriesRenderer xYMultipleSeriesRenderer = this.c;
        if (xYMultipleSeriesRenderer != null) {
            if ((xYMultipleSeriesRenderer.U() || this.c.V()) && this.c.W()) {
                this.o.setColor(k);
                int max = Math.max(this.j, Math.min(width, height) / 7);
                this.j = max;
                float f = i2 + height;
                float f2 = i3 + width;
                this.f.set(i - (max * 3), f - (max * 0.775f), f2, f);
                RectF rectF = this.f;
                int i4 = this.j;
                canvas.drawRoundRect(rectF, i4 / 3, i4 / 3, this.o);
                int i5 = this.j;
                float f3 = f - (i5 * 0.625f);
                canvas.drawBitmap(this.g, f2 - (i5 * 2.75f), f3, (Paint) null);
                canvas.drawBitmap(this.h, f2 - (this.j * 1.75f), f3, (Paint) null);
                canvas.drawBitmap(this.i, f2 - (this.j * 0.75f), f3, (Paint) null);
            }
        }
    }

    @Override // android.view.View
    public boolean onTouchEvent(MotionEvent motionEvent) {
        GestureDetector gestureDetector = this.a;
        return gestureDetector != null ? gestureDetector.onTouchEvent(motionEvent) : super.onTouchEvent(motionEvent);
    }

    public void setZoomRate(float f) {
        org.achartengine.internal.a.d dVar = this.l;
        if (dVar == null || this.m == null) {
            return;
        }
        dVar.a(f);
        this.m.a(f);
    }

    public void b() {
        org.achartengine.internal.a.d dVar = this.l;
        if (dVar != null) {
            dVar.b();
            f();
        }
    }

    public void c() {
        org.achartengine.internal.a.d dVar = this.m;
        if (dVar != null) {
            dVar.b();
            f();
        }
    }

    public void d() {
        org.achartengine.internal.a.b bVar = this.n;
        if (bVar != null) {
            bVar.b();
            f();
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public RectF e() {
        return this.f;
    }

    public void f() {
        this.e.post(new Runnable() { // from class: org.achartengine.internal.GraphicalView.1
            @Override // java.lang.Runnable
            public void run() {
                GraphicalView.this.invalidate();
            }
        });
    }

    public void a(final int i, final int i2, final int i3, final int i4) {
        this.e.post(new Runnable() { // from class: org.achartengine.internal.GraphicalView.2
            @Override // java.lang.Runnable
            public void run() {
                GraphicalView.this.invalidate(i, i2, i3, i4);
            }
        });
    }

    public Bitmap g() {
        if (!isDrawingCacheEnabled()) {
            setDrawingCacheEnabled(true);
        }
        return getDrawingCache();
    }

    public ValueObject a(float f, float f2) {
        ValueObject a = this.b.a(f, f2);
        postInvalidate();
        return a;
    }
}
